package com.yjd.comm.util;

import com.yjd.comm.doctor.model.DoctorModel;
import com.yjd.comm.enums.GenderEnum;
import com.yjd.comm.org.model.OrganizationModel;
import com.yjd.comm.project.model.ProjectCaseModel;
import com.yjd.comm.project.model.ProjectModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 构建返回结果集
 * Created by yangchangyan on 2017/7/12.
 */
public class ResultMapBuilder {
    public static Map<String, Object> build(Object obj){
        Map<String, Object> result = new HashMap<String, Object>();
        if(null == obj){
            return result;
        }

        if (obj instanceof DoctorModel) {
            return buildDoctorMap((DoctorModel)obj, result);
        }

        if (obj instanceof ProjectModel) {
            return buildProjectMap((ProjectModel)obj, result);
        }

        if (obj instanceof OrganizationModel) {
            return buildOrgMap((OrganizationModel)obj, result);
        }

        if (obj instanceof ProjectCaseModel) {
            return buildCaseMap((ProjectCaseModel)obj, result);
        }

        return result;
    }

    /**
     * 处理医生的返回信息
     *
     * @param
     * @return
     * @throws
     */
    private static Map<String, Object> buildDoctorMap(DoctorModel doctor, Map<String, Object> result){
        result.put("doctor_id", doctor.getDoctor_id());
        result.put("doctor_name", doctor.getName());
        result.put("portrait_path", ServletUtil.getFileUrl(doctor.getPortrait_path()));
        result.put("gender", GenderEnum.parse(doctor.getGender()).getLabel());
        result.put("org_id", doctor.getOrg_id());
        result.put("org_name", "");
        result.put("detail_id", doctor.getDetail_id());
        result.put("intro", doctor.getIntro());
        result.put("phone_number", doctor.getPhone_number());
        result.put("position", TypeShowUtils.getDoctorTitleShow(doctor.getPosition()));
        result.put("tags", "");
        return result;
    }

    /**
     * 处理项目的返回信息
     *
     * @param
     * @return
     * @throws
     */
    private static Map<String, Object> buildProjectMap(ProjectModel project, Map<String, Object> result){
        result.put("project_id", project.getProject_id());
        result.put("project_name", project.getProject_name());
        result.put("project_price", project.getProject_price());
        result.put("act_price", project.getAct_price());
        result.put("payment", project.getPayment());
        result.put("loan_price", project.getLoan_price());
        result.put("project_pic", ServletUtil.getFileUrl(project.getProject_pic()));
        result.put("doctor_id", project.getDoctor_id());
        result.put("org_id", project.getOrg_id());
        result.put("org_name", "");
        result.put("category_name", "");
        result.put("reservation_count", project.getReservation_count());
        result.put("detail_id", project.getDetail_id());
        result.put("category_id", project.getCategory_id());
        result.put("intro", project.getIntro());
        return result;
    }

    /**
     * 处理机构的返回信息
     *
     * @param
     * @return
     * @throws
     */
    private static Map<String, Object> buildOrgMap(OrganizationModel org, Map<String, Object> result){
        result.put("org_id", org.getOrg_id());
        result.put("org_name", org.getOrg_name());
        result.put("org_pic", ServletUtil.getFileUrl(org.getOrg_pic()));
        result.put("org_city", org.getOrg_city());
        try {
            result.put("org_address", CityUtil.getFullCityNames(org.getOrg_city(), "") + org.getOrg_address());
        } catch (Exception e) {
            result.put("org_address", org.getOrg_address());
        }
        result.put("org_type", TypeShowUtils.getOrgTypeShow(org.getOrg_type()));
        result.put("org_major_business", org.getOrg_major_business());
        result.put("intro", org.getIntro());
        result.put("detail_id", org.getDetail_id());
        result.put("org_tel_number", org.getOrg_tel_number());
        return result;
    }

    /**
     * 处理案例的返回信息
     *
     * @param
     * @return
     * @throws
     */
    private static Map<String,Object> buildCaseMap(ProjectCaseModel pcm, Map<String, Object> result) {
        result.put("case_name", pcm.getCase_name());
        result.put("case_content", pcm.getCase_content());
        result.put("case_pic", ServletUtil.getFileUrl(pcm.getCase_pic()));
        result.put("create_time", DateUtil.timestampToDateString(pcm.getCreate_time(), DateUtil.PATTERN_yyyy_MM_dd_HH_mm_ss));
        return result;
    }
}
